how does selection sort work